<template >
  <div id="login">
   <div class="login">
     <!-- 显示头像 -->
    <div class="login_img">
      <img src="~assets/logo.png" alt="">
    </div>
    <el-form  class="fromlog"  :model="fromData" :rules="fromRules" ref="fromRef">
      <!-- 用户名称 -->
        <el-form-item prop="username" >
          <el-input v-model="fromData.username" prefix-icon="el-icon-user-solid" ></el-input>
        </el-form-item>
        <!-- 用户密码 -->
         <el-form-item prop="password" >
          <el-input v-model="fromData.password"  prefix-icon="el-icon-s-cooperation"></el-input>
        </el-form-item>
        <div class="btns">
          <el-button type="primary" @click="btnlu">登陆</el-button>
          <el-button type="info" @click="btreset">重置</el-button>
        </div>
    </el-form>
   </div>
  </div>
</template>
<script>
import {getlogin} from 'network/login'
export default {
  name:'login',
  data() {
    return {
      fromData:{
        username:'admin',
        password:'123456'
      },
      fromRules:{
        username: [
            { required: true, message: '请输用户名称', trigger: 'blur' },
            { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
          ],
        password: [
            { required: true, message: '请输用户密码', trigger: 'blur' },
            { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
          ],
      }
    }
  },
  methods: {
   btreset(){
     this.$refs.fromRef.resetFields()
   },
   btnlu(){
     const name=this.fromData
     getlogin(name.username,name.password).then(res=>{
       console.log(res);
       if(res.meta.status!=200) return this.$message.error('登陆失败')
       window.sessionStorage.setItem('token',res.data.token)
       this.$router.push('/home')
       return this.$message.success('登陆成功')
     })
   }
  },
}
</script>
<style lang="less" scoped>
.login{
  width: 450px;
  height: 300px;
  background-color: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  box-shadow: 3px 3px 2px rgb(216, 209, 209)
}
.login_img{
  width: 150px;
  height: 150px;
  border: 2px solid #eee;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 0 5px #eee;
  transform: translate(-50%,-50%);
  position: absolute;
  left: 50%;
  img{
    width: 100%;
    height: 100%;
    background-color: #eee;
    border-radius: 50%;
  }
}
.fromlog{
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 10px;
  box-sizing: border-box;
  padding-bottom: 20px;
  .btns{
    justify-content: flex-end;
    display: flex;
  }
}
</style>


